22 template <class T
> string
toStr(const T
&x
){ stringstream s
; s
<< x
; return s
.str(); }
23 template <class T
> int toInt(const T
&x
){ stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
27 #define D(x) cout << #x " = " << (x) << endl
29 int next(const string
&s
, int i
);
30 int prev(const string
&s
, int i
);
32 bool looksLike0000(const string
&s
, int i
){
33 for (; i
<s
.size(); ++i
) if (s
[i
] != '0') return false;
37 bool looksLike1000(const string
&s
, int i
){
38 if (s
[i
] != '1') return false;
39 for (++i
; i
<s
.size(); ++i
) if (s
[i
] != '0') return false;
43 int next(const string
&s
, int i
){
44 if (i
== s
.size() - 1) return i
;
46 if (looksLike1000(s
, i
+1)){
52 if (looksLike0000(s
, i
+1)){
60 int prev(const string
&s
, int i
){
61 if (i
== s
.size() - 1) return i
;
63 if (looksLike0000(s
, i
+1)){
69 if (looksLike1000(s
, i
+1)){
80 while (cin
>> m
>> s
&& m
){
82 int where
= next(s
, 0);
83 s
[where
] = s
[where
] == '0' ? '1' : '0';